package com.atxwq.shop.manager.controller;

import com.atxwq.shop.manager.serivce.ProductSpecService;
import com.atxwq.shop.model.entity.product.Brand;
import com.atxwq.shop.model.entity.product.ProductSpec;
import com.atxwq.shop.model.vo.common.Result;
import com.atxwq.shop.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 商品规格管理
 * @Date 2025/5/14 09:42
 * @Created by 12336
 */

@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {

    @Autowired
    private ProductSpecService productSpecService;


    /**
     * 分页查询商品规格
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<ProductSpec>> findByPage(@PathVariable Integer page, @PathVariable Integer limit){
        PageInfo<ProductSpec> pageInfo = productSpecService.findByPage(page, limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加商品规格
     * @param productSpec
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改商品规格
     * @param productSpec
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody ProductSpec productSpec){
        productSpecService.update(productSpec);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除商品规格
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Long id){
        productSpecService.delete(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询所有商品规格
     * @return
     */
    @GetMapping("findAll")
    public Result findAll(){
        List<ProductSpec> list = productSpecService.findAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
}
